﻿using System;
using System.IO;

namespace RenameApp
{
    public static class TextHandler
    {
        /// <summary>
        /// 替换文字
        /// </summary>
        public static string ReplaceWord(string originalWord, string oldValue, string newValue)
        {
            if (string.IsNullOrEmpty(originalWord) || string.IsNullOrEmpty(oldValue))
            {
                return originalWord ?? "";
            }
            return originalWord.Replace(oldValue, newValue ?? "");
        }

        /// <summary>
        /// 添加前缀
        /// </summary>
        public static string AddPrefix(string originalWord, string prefix)
        {
            return string.IsNullOrEmpty(prefix) ? originalWord : prefix + originalWord;
        }

        /// <summary>
        /// 添加后缀
        /// </summary>
        public static string AddSuffix(string originalWord, string suffix)
        {
            if (string.IsNullOrEmpty(suffix)) return originalWord;

            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(originalWord);
            string extension = Path.GetExtension(originalWord);
            return fileNameWithoutExtension + suffix + extension;
        }

        /// <summary>
        /// 添加序号
        /// </summary>
        public static string AddIndex(string originalWord, int index, int totalFiles)
        {
            int digits = totalFiles.ToString().Length;
            string indexStr = index.ToString().PadLeft(digits, '0');
            return $"{indexStr}_{originalWord}";
        }

        /// <summary>
        /// 更改大小写
        /// </summary>
        public static string ChangeCase(string originalWord, CaseType caseType)
        {
            switch (caseType)
            {
                case CaseType.UpperCase:
                    return originalWord.ToUpper();
                case CaseType.LowerCase:
                    return originalWord.ToLower();
                case CaseType.FirstLetterUpper:
                    return System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(originalWord.ToLower());
                default:
                    return originalWord;
            }
        }
    }
    public enum CaseType
    {
        UpperCase,
        LowerCase,
        FirstLetterUpper
    }
}